const { ccclass, property } = cc._decorator;

@ccclass
export default class History_itemTs extends cc.Component {

    @property(cc.Label)
    labelTitle1: cc.Label = null;

    @property(cc.Label)
    labelTitle2: cc.Label = null;

    @property(cc.Label)
    labelTitle3: cc.Label = null;

    @property(cc.Label)
    labelTitle4: cc.Label = null;

    @property(cc.Label)
    labelTitle5: cc.Label = null;

    public setInfo(data) {
        this.labelTitle1.string = this.timestampToTime(data.created_at);
        this.labelTitle2.string = data.order_id;
        this.labelTitle3.string = (Number(data.coin) / 100).toString();
        this.labelTitle4.string = data.tax_amount;
        this.labelTitle5.string = this.getStatus(data.status);
    }

    /**2014-06-18 10:33:24 */
    public timestampToTime(timestamp): string {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
        var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
        var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
        var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
        var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
        return Y + M + D + "\n" + h + m + s;
    }

    public getStatus(type: number) {
        let typeString: string = "";
        switch (type) {
            case 0:
                typeString = "Pending";
                break;
            case 1:
                typeString = "Success";
                break;
            case 2:
                typeString = "Failure";
                break;
        }
        return typeString;
    }

}
